package com.zzyy.study.controller;

import cn.hutool.core.util.IdUtil;
import com.zzyy.study.common.Result;
import com.zzyy.study.common.ResultUtils;
import com.zzyy.study.config.RabbitMQConfiguration;
import com.zzyy.study.entities.OrderMsg;
import com.zzyy.study.mq.sender.IMsgSender;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @auther zzyy
 * @create 2024-08-28 23:07
 */
@RestController
public class OrderControllerByInOrder
{

    @Resource
    private IMsgSender msgSender;

    /**
     * 发送顺序消息
     *
     * @return
     */
    @PostMapping("/sendSequential")
    public Result<Void> sendSequential() {
        String orderId = IdUtil.fastSimpleUUID();

        List<String> list = Arrays.asList("订单创建消息",
                "订单支付消息",
                "订单已发货",
                "买家确认收货",
                "订单已完成");

        for (String type : list)
        {
            msgSender.sendSequentialWithBody(
                    orderId,
                    RabbitMQConfiguration.Order.EXCHANGE,
                    RabbitMQConfiguration.Order.ROUTING_KEY,
                    OrderMsg.builder().orderId(orderId).type(type).build());

        }

        return ResultUtils.success();
    }
}
